<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
	<div class="wrapper wrapper-content ">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="signupForm">
							<div class="form-group">	
								<label class="col-sm-2 control-label">评分年度：</label>
								<div class="col-sm-4">
									<input id="deptId"  readonly="readonly" th:value="${year}" class="form-control " type="text" >
								</div>
								<label class="col-sm-2 control-label">评分月度：</label>
								<div class="col-sm-4">
									<input id="deptId"   readonly="readonly" th:value="${month}" class="form-control " type="text">
								</div>
							</div>
							<div class="form-group" th:each="dept :${deptList}">
								<input class="hidden" th:name="'list['+${deptStat.index}+'].teamName'" th:value="${dept.name}"/>	
								<input class="hidden" th:name="'list['+${deptStat.index}+'].deptId'" th:value="${dept.deptId}"/>	
								<label class="col-sm-2 control-label" th:text="${dept.name}"></label>
								<!-- <div class="col-sm-5">
									<input  th:name="'list['+${deptStat.index}+'].ord'" class="form-control ord" type="text" placeholder="排名">
								</div> -->
								<div class="col-sm-10">
									<input  th:name="'list['+${deptStat.index}+'].score'" required="required"  class="form-control score" type="text" placeholder="评分">
									<span class="msg" style="color: red"></span>
								</div>
								<!-- <div class="col-sm-4">
									<input name="deptId" class="form-control" type="text">
								</div> -->
							</div>
							<div class="form-group">
								<div class="col-sm-8 col-sm-offset-3">
									<button type="button" id="submit" class="btn btn-primary">提交</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
	</div>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript" src="/js/appjs/per/team/add.js"></script>
	<script>
	$(function(){
		var sv;
		var ave = 0;
		$('.score').focus(function(){
			sv= $(this).val();
		})
		$('.score').change(function(){
			
			var val=$(this).val();
			console.log(val)
			var reg = /^100(\.00)?$|^(\d|[1-9]\d)(\.\d{1,2})?$/;
			//alert(!reg.test(val))
			if(!reg.test(val)){
				layer.alert("请输入0-100的数值")
				$(this).val(sv);
				return false;
			}
			
			$('.msg').html("");
			var num = 0;
			var sum = 0;
			
			$('.score').each(function(){
				var score = $.trim($(this).val());
				//console.log(score)
				if(score != '' && score != 'undefined' && score != null){
					num++;
					sum += parseFloat(score);
				}
			})
			ave = (sum/num).toFixed(2);
			 
			var v = (num+1)*90-sum;
			var v2 = (num)*90- (sum-$(this).val())
			$(this).next().html("当前均分  "+ave+", 还需评分  "+v+",或将当前评分改为  "+v2)
			//v+sum/num++ = 90
			//layer.msg("当前均分为"+ave+",下一个人的评分为"+v+"则可以满足平均分为90分");
		})
	})
	
	function getScore (ord){
		return 100-ord+1;
	}
	
	function save() {
		var num = 0;
		var sum = 0;
		
		$('.score').each(function(){
			var score = $.trim($(this).val());
			//console.log(score)
			if(score != '' && score != 'undefined' && score != null){
				num++;
				sum += parseFloat(score);
			}
		})
		ave = (sum/num).toFixed(2);
		if(ave != 90){
			layer.alert("请确保所有人的平均分为90分")
			return;
		} 
		$.ajax({
			cache : true,
			type : "POST",
			url : "/per/team/saveScoreByMan",
			data : $('#signupForm').serialize(),// 你的formid
			async : false,
			error : function(request) {
				parent.layer.alert("Connection error");
			},
			success : function(data) {
				if (data.code == 0) {
					location.href="/tips/success"

				} else {
					location.href="/tips/fail"
				}

			}
		});

	}
	</script>
</body>

</html>
